package examples
{
	import com.dreamana.components.Label;
	import com.dreamana.components.List;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	public class ListExample extends Sprite
	{
		private var list:List;
		private var output:Label;
		
		public function ListExample()
		{
			stage? init() : this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(event:Event=null):void
		{
			if(event) this.removeEventListener(event.type, init);
			
			this.x = 320;
			this.y = 0;
			
			/* List usage */
			
			list = new List(300, 160);
			list.setPosition(10, 10);
			this.addChild(list);
			
			//Data
			list.setItems([
				{label:"Apple Pie", data:0},
				{label:"Big Mac", data:1},
				{label:"Coffee", data:2},
				{label:"Dip Cone", data:3},
				{label:"Egg Roll", data:4},
				{label:"French Fries", data:5},
				{label:"Green Salad", data:6},
				{label:"Hot Chocolate", data:7},
				{label:"Iced Tea", data:8},
				{label:"Junior Burger", data:9}
			]);
			
			//Styling
			list.setStyle("cell-height", 24);
			list.vscrollbar.setStyle("track-color", 0xcccccc);
						
			//Deselectable
			list.deselectable = true;
			
			//Status
			output = new Label(240, 24, null, "", list.x, list.y + list.height + 10);
			this.addChild(output);
			
			//onSelect Event
			list.addEventListener(Event.SELECT, onSelect);
		}
		
		private function onSelect(event:Event):void
		{
			if(list.selectedIndex >= 0) {
				output.text = "You selected "+ list.selectedItem["label"] + " (ID:" + list.selectedItem["data"] + ")";
			}
			else {
				output.text = "Nothing is selected.";
			}
		}
	}
}